package com.woniu.common.util;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.ArrayList;

/**
 * @Author: Frank
 * @Date: 2022/4/17  12:12
 * @Description:
 */
public class UserGenerator {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Pur_PurchaseReturn");
        FastAutoGenerator.create("jdbc:mysql://59.110.232.116:3306/nbplus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC", "root", "root")
                .globalConfig(builder -> {
                    builder.author("Frank")      //作者
                            .outputDir("D://ideaIU//workSpace//sell//wn-purchaseReturn//src//main//java")      //输出路径(写到java目录)
                            .enableSwagger()    //开启swagger
                            .commentDate("yyyy-MM-dd")
                            .fileOverride();    //开启覆盖之前生成的文件
                })
                .packageConfig(builder -> {
                    builder.parent("com.wn")
                            .moduleName("purchaseReturn")
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .mapper("mapper")
                            .xml("mapper.xml");
                })
                .strategyConfig(builder -> {
                    builder.addInclude(list)
                            .addTablePrefix("p_")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .entityBuilder()
                            .enableLombok()
                            .logicDeleteColumnName("deleted")
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .formatFileName("%sController")
                            .enableRestStyle()
                            .mapperBuilder()
                            .superClass(BaseMapper.class)
                            .formatMapperFileName("%sMapper")
                            .enableMapperAnnotation()
                            .formatXmlFileName("%sMapper");
                })
                .templateEngine(new FreemarkerTemplateEngine())     // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
